using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using BUS;
using DTO;

namespace Presentation
{
    public partial class frmThongKe : Form
    {
        public frmThongKe()
        {
            InitializeComponent();
        }

        private void thoat_btn_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void thongke_btn_Click(object sender, EventArgs e)
        {

        }

        private void btnThongKe_Click(object sender, EventArgs e)
        {
            string strSQL;
            int Thang;
            MuaSachBus b = new MuaSachBus();
            switch (tabControl1.SelectedIndex)
            {
                case 0:
                    {
                        try
                        {
                            strSQL = "SELECT Month(NgayMua) AS Thang, Sum(GiaSach) as TongSoTien FROM Mua_Sach,Dau_Sach Where Mua_Sach.MaDauSach = Dau_Sach.MaDauSach GROUP BY Month(NgayMua)";
                            dtgvThongKeThang.DataSource = b.ThongKe(strSQL);
                            if (dtgvThongKeThang.RowCount == 0)
                            {
                                MessageBox.Show("Khong tim thay du lieu", "Thong bao");
                            }
                            
                        }
                        catch (System.Exception)
                        {
                            MessageBox.Show("Khong tim thay du lieu", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    break;
                case 1:
                    {
                        try
                        {
                            Thang  = cmbThang1.SelectedIndex + 1;
                            strSQL = "SELECT Mua_Sach.MaDauSach,TenDauSach,Count(*) as SoLuong FROM Mua_Sach,Dau_Sach WHERE Month(NgayMua)=" + Thang.ToString() + " and Mua_Sach.MaDauSach=Dau_Sach.MaDauSach GROUP BY Mua_Sach.MaDauSach,TenDauSach ORDER BY count(*) DESC";
                            dtgvThongKeSoLuong.DataSource = b.ThongKe(strSQL);
                            if (dtgvThongKeSoLuong.RowCount == 0)
                            {
                                MessageBox.Show("Khong tim thay du lieu", "Thong bao");
                            }
                        }
                        catch (System.Exception)
                        {
                            MessageBox.Show("Khong tim thay du lieu", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                    }
                    break;
                case 2:
                    {
                        try
                        {
                            Thang = cmbThang2.SelectedIndex + 1;
                            strSQL = "Select Mua_Sach.MaKhachHang,HoTen, count(*) as SoLuongSachMua from KhachHang,Mua_Sach where Month(NgayMua)=" + Thang.ToString() + "and KhachHang.MaKhachHang=Mua_Sach.MaKhachHang group by Mua_Sach.MaKhachHang,HoTen order by count(*) DESC";
                            dtgvThongKeNguoiMua.DataSource = b.ThongKe(strSQL);
                            if (dtgvThongKeNguoiMua.RowCount == 0)
                            {
                                MessageBox.Show("Khong tim thay du lieu", "Thong bao");
                            }
                        }
                        catch (System.Exception)
                        {
                            MessageBox.Show("Khong tim thay du lieu", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                    }
                    break;
            }

        }
    }
}